package org.arithmetic.other;

/**
 * Created by LUOLIANG on 2016/8/26.
 * Get Greatest Common Divisor
 */
public class GreatestCommonDivisor {

    /**
     * 辗转相除法求最大公约数
     *
     * @param a
     * @param b
     * @return
     */
    public static Integer getGCD(int a, int b) {
        if (a % b == 0) {
            return b;
        }

        return getGCD(b, a % b);
    }

    public static void main(String[] args) {
        int a = 885;
        int b = 285;

        System.out.println("最大公约数：(" + a + "," + b + ") = " + getGCD(b, a));
        System.out.println("最小公倍数: [" + a + "," + b + "] = " + a * b / getGCD(a, b));
    }
}
